<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>小兔鲜儿 - 新鲜 惠民 快捷!</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="renderer" content="webkit">
  <link rel="shortcut icon" href="../favicon.ico">
  <link rel="stylesheet" href="../css/common.css">
  <link rel="stylesheet" href="../css/login.css">
  <link rel="stylesheet" href="https://at.alicdn.com/t/font_2143783_iq6z4ey5vu.css">
</head>

<body>
  <!-- 登录头部 -->
  <div class="xtx-login-header">
    <h1 class="logo"></h1>
    <a class="home" href="./index.html">进入网站首页</a>
  </div>
  <!-- 登录内容 -->
  <div class="xtx-login-main">
    <div class="wrapper">
      <form action="">
        <div class="box">
          <div class="tab-nav">
            <a href="javascript:;" class="active" data-id="0">账户登录</a>
            <a href="javascript:;" data-id="1">二维码登录</a>
          </div>
          <div class="tab-pane">
            <div class="link">
              <a href="javascript:;">手机验证码登录</a>
            </div>
            <div class="input">
              <span class="iconfont icon-zhanghao"></span>
              <input required type="text" placeholder="请输入用户名称/手机号码" name="username">
            </div>
            <div class="input">
              <span class="iconfont icon-suo"></span>
              <input required type="password" placeholder="请输入密码" name="password">
            </div>
            <div class="agree">
              <label for="my-checkbox">
                <input type="checkbox" value="1" id="my-checkbox" class="remember" name="agree">
                <span class="iconfont icon-xuanze"></span>
              </label>
              我已同意 <a href="javascript:;">《服务条款》</a href="javascript:;"> 和 <a>《服务条款》</a>
            </div>
            <div class="button clearfix">
              <button type="submit" class="dl">登 录</button>
              <!-- <a class="dl" href="./center.html">登 录</a> -->
              <a class="fl" href="./forget.html">忘记密码？</a>
              <a class="fr" href="./register.html">免费注册</a>
            </div>
          </div>
          <div class="tab-pane" style="display: none;">
            <img class="code" src="../images/code.png" alt="">
          </div>
        </div>
      </form>
    </div>
  </div>
  <!-- 登录底部 -->
  <div class="xtx-login-footer">
    <!-- 版权信息 -->
    <div class="copyright">
      <p>
        <a href="javascript:;">关于我们</a>
        <a href="javascript:;">帮助中心</a>
        <a href="javascript:;">售后服务</a>
        <a href="javascript:;">配送与验收</a>
        <a href="javascript:;">商务合作</a>
        <a href="javascript:;">搜索推荐</a>
        <a href="javascript:;">友情链接</a>
      </p>
      <p>CopyRight &copy; 小兔鲜儿</p>
    </div>
  </div>
  <script>

    // 获取标签
    const user = document.querySelector('.icon-zhanghao');
    const password = document.querySelector('.icon-suo');
    const username = document.querySelector('[name=username]');
    const inptupassword = document.querySelector('[name=password]');
    const btn = document.querySelector('.dl');
    const remember = document.querySelector('.remember');

    // tab栏切换标签
    const tabnav = document.querySelector('.tab-nav');
    const tabpane = document.querySelectorAll('.tab-pane');

    // 获取本地存储用户数据
    const arrData = JSON.parse(localStorage.getItem('userData') || []);

    // 创建正则验证条件
    /* const regname = /^[a-zA-Z0-9_-]{7,15}$/;
    const regpassword = /^[0-9]{6,18}$/; */
    btn.addEventListener('click', function (e) {
      e.preventDefault();
      username.focus();
      username.blur();
      inptupassword.focus();
      inptupassword.blur();
      const pass = document.querySelectorAll('.pass');
      if (pass.length === 2 && remember.checked === true) {
        location.href = './index.html';
      } else if (remember.checked === false) {
        alert('请勾选用户协议！');
      } else {
        alert('请仔细填写用户名和密码！');
      }
    });

    // 用户名失去焦点事件
    username.addEventListener('blur', function (e) {
      arrData.forEach(v => {
        if (v.username === username.value.trim()) {
          username.previousElementSibling.style.backgroundColor = '#68bcb0';
          username.previousElementSibling.innerHTML = '✔'
          username.classList.add('pass');
        } else {
          username.previousElementSibling.style.backgroundColor = 'red';
          username.previousElementSibling.innerHTML = '❌';
        }
      });

    })
    // 密码失去焦点事件
    inptupassword.addEventListener('blur', function (e) {
      arrData.forEach(v => {
        if (v.password === inptupassword.value.trim()) {
          inptupassword.previousElementSibling.style.backgroundColor = '#68bcb0';
          inptupassword.previousElementSibling.innerHTML = '✔'
          inptupassword.classList.add('pass');
        } else {
          inptupassword.previousElementSibling.style.backgroundColor = 'red';
          inptupassword.previousElementSibling.innerHTML = '❌'
        }
      });

    })

    // tab栏切换
    tabnav.addEventListener('click', function (e) {
      if (e.target.nodeName === 'A') {
        document.querySelector('.tab-nav .active').classList.remove('active');
        e.target.classList.add('active');
        for (let index = 0; index <= tabpane.length - 1; index++) {
          tabpane[index].style.display = 'none';
          tabpane[e.target.dataset.id].style.display = 'block';
        }
      }
    })

  </script>
</body>

</html>